home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-16 | 2.2 KB | 54 lines | [TEXT/MPS ] |
- #-----------------------------------------------------------------------------------------------------------------------------------------------------
- # SS (Search and Set)
- # MPW Shell Script
- # Written by C.K. Haun
- # Modified by Gina Cherry • August 16,1991
- # Copyright: © 1991 by Apple Computer, Inc., all rights reserved.
- #
- # Usage:
- # SS [fileToFind]
- #
- # Function:
- # Search for a file and set directory to the directory containing the file.
- # If a file is not specified on the command line, a dialogue will prompt the user for a file name.
- #-----------------------------------------------------------------------------------------------------------------------------------------------------
-
- # Don't exit on error.
- Set Exit 0
-
- # If a parameter was given, set fileToFind to the parameter.
- If {#} == 1
- Set fileToFind "{1}"
-
- # Otherwise, display a dialogue asking for file name. Exit script if Cancel is chosen.
- Else
- Set fileToFind "`Request "Program to find:" || Echo`"
- Exit If "{fileToFind}" == ""
- End
-
- Echo "Finding file ∂"{fileToFind}∂"" >> "{Worksheet}"
-
- # Search for fileToFind, starting at the {MPW} directory.
- # Set the dirIn to the full pathname of fileToFind.
- Set dirIn "`whereis -s "{MPW}" -c "{fileToFind}"`"
-
- # If fileToFind is not found, print error message and exit script.
- If "{dirIn}" == ""
- Echo "### {0}: Couldn't find file ∂"{fileToFind}∂"" >> Dev:StdErr
- Exit 1
- End
-
-
- # Pick out the directory name from the file's full path name.
- # The Evaluate statement is used for its side effect of allowing the shell access to ® variables.
- # The statement picks out the name of the directory containing fileToFind from the regular
- # expression, and assigns the directory name to ®1. ®1 can then be used as a shell variable.
- #
- # Note: dirIn will be a string enclosed in single quotes if the file path name includes any special
- # characters, such as spaces. Therefore, the regular expression to which dirIn is compared must
- # begin with the characters ∂'*, which means "0 or more single quotations marks".
- (Evaluate "{dirIn}" =~ /∂'*(([¬:]*:)+)®1[¬:]*/ ) ∑ Dev:Null
-
-
- Echo "Setting directory to ∂"{®1}∂"" >> "{Worksheet}"
- SetDirectory "{®1}"